﻿<?php
include_once('common/header.php');	
include_once('member/filter.php');	
$intPage		= $objRequest->getParam('page', 1);
$intLimit		= MEMBER_SEARCH_LIMIT;
$intTotal		= 0;
$intOff			= (($intPage-1) * $intLimit);
$objMember		= new Member();
$intGender		= $AppUI->gender;
if(!isset($intAjax)) {
	$intOwnerId	= $AppUI->id;
}
$arrParams		= $objRequest->getParams();
$strKeyword		= isset($arrParams['keyword']) ? $arrParams['keyword'] : '';
$intLookGender	= isset($arrParams['gender']) ? $arrParams['gender'] : 0;
$intAgeFrom		= isset($arrParams['afrom']) ? $arrParams['afrom'] : 0;
$intAgeTo		= isset($arrParams['ato']) ? $arrParams['ato'] : 0;
$intAvatar		= isset($arrParams['avatar']) ? $arrParams['avatar'] : 0;
if(!isset($intAjax)) {
	$arrProvince	= isset($arrParams['province']) ? $arrParams['province'] : array();
	$arrOccupation	= isset($arrParams['occupation']) ? $arrParams['occupation'] : array();
	$arrReligion	= isset($arrParams['religion']) ? $arrParams['religion'] : array();
	$arrMarital		= isset($arrParams['marital']) ? $arrParams['marital'] : array();
	$arrPreference	= isset($arrParams['preference']) ? $arrParams['preference'] : array();
	$intCountProv	= count($arrProvince);
	$intCountProv	= count($arrProvince);
	$intCountOccu	= count($arrOccupation);
	$intCountReli	= count($arrReligion);
	$intCountMari	= count($arrMarital);
	$intCountPref	= count($arrPreference);
	$strProvince	= (isset($arrProvince) && ($intCountProv == 0 || $intCountProv == $intProvince)) ? '' : Vfriend_Function::convertArrToStr($arrProvince);
	$strOccupation	= (isset($arrOccupation) && ($intCountOccu == 0 || $intCountOccu == $intOccupation)) ? '' : Vfriend_Function::convertArrToStr($arrOccupation);
	$strReligion	= (isset($arrReligion) && ($intCountReli == 0 || $intCountReli == $intReligion)) ? '' : Vfriend_Function::convertArrToStr($arrReligion);
	$strMarital		= (isset($arrMarital) && ($intCountMari == 0 || $intCountMari == $intMarital)) ? '' : Vfriend_Function::convertArrToStr($arrMarital);
	$strPreference	= (isset($arrPreference) && ( $intCountPref == 0 || $intCountPref == $intPreference)) ? '' : Vfriend_Function::convertArrToStr($arrPreference);
} else {
	$strProvince	= isset($arrParams['province']) ? $arrParams['province'] : '';
	$strOccupation	= isset($arrParams['occupation']) ? $arrParams['occupation'] : '';
	$strReligion	= isset($arrParams['religion']) ? $arrParams['religion'] : '';
	$strMarital		= isset($arrParams['marital']) ? $arrParams['marital'] : '';
	$strPreference	= isset($arrParams['preference']) ? $arrParams['preference'] : '';
}
$arrResult		= $objMember->search($intOwnerId, $strKeyword, $intAgeFrom, $intAgeTo, $intLookGender, $intAvatar, $strProvince, $strMarital, $strOccupation, $strReligion, $strPreference, $intOff, $intLimit, $intTotal);
if($intTotal >= MAX_DISPLAY) {
	$intTotal	= MAX_DISPLAY;
}
$this->view->arrResult		= $arrResult;
$this->view->params			= $arrParams;
$this->view->arrResult		= $arrResult;
$this->view->intTotalPage	= ceil($intTotal / $intLimit);
$this->view->intPage 		= $intPage;			
$this->view->intOwnerId 	= $intOwnerId;
?>